package main

import (
	"encoding/json"
	"fmt"
)

type Cache interface {
	Set(key string, value any)
	Get(key string) any
}

type Redis struct {
	dict map[string]any
}

func (r *Redis) Set(key string, value any) {
	r.dict[key] = value
}

func (r *Redis) Get(key string) any {
	return r.dict[key]
}

type MongoDB struct {
	doc map[string]string
}

func (o *MongoDB) Set(key string, value any) {
	data, _ := json.Marshal(value)
	o.doc[key] = string(data)
}

func (o *MongoDB) Get(key string) any {
	return o.doc[key]
}

type CacheFactory interface {
	Create() Cache
}

type RedisFactory struct{}

func (f *RedisFactory) Create() Cache {
	return &Redis{
		dict: make(map[string]any),
	}
}

type MongoFactory struct{}

func (f *MongoFactory) Create() Cache {
	return &MongoDB{
		doc: make(map[string]string),
	}
}

func main() {
	rf := &RedisFactory{}
	mf := &MongoFactory{}
	r := rf.Create()
	m := mf.Create()
	data := map[string]any{
		"key":   "array",
		"value": []int{1, 2, 3, 4, 5},
	}
	r.Set("data", data)
	fmt.Println(r.Get("data"))
	m.Set("data", data)
	fmt.Println(m.Get("data"))
}
